//
//  UserInfoView.swift
//  weibo
//
//  Created by tomato on 2023/9/28.
//

import UIKit

class UserInfoView: UIView {
    
    // MARK: - 懒加载
    //头像
    lazy var headImageView: UIImageView = {
        let headImageView = UIImageView()
        return headImageView
    }()
    // 会员等级
    lazy var membershipImageView: UIImageView = {
        let membershipImageView = UIImageView(image: UIImage(named: "common_icon_membership"))
        return membershipImageView
    }()
    lazy var avatarImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    ///用户名称
    lazy var nameL: UILabel = {
        let label = UILabel()
        // 设置label大小
        label.font = UIFont.systemFont(ofSize: 14)
        // 设置颜色
        label.textColor = UIColor.black
        return label
    }()
    // 来源
    lazy var sourceLabel: UILabel = {
        let lab = UILabel()
        lab.font = UIFont.systemFont(ofSize: 10)
        lab.textColor = UIColor.gray
        return lab
    }()
    
    //时间
    lazy var timeLabel: UILabel = {
        let timeLabel = UILabel()
        timeLabel.textColor = UIColor.gray;
        timeLabel.font = UIFont.systemFont(ofSize: 10)
        return timeLabel
    }()
    
    //关注
    lazy var followBtn: UIButton = {
        let followBtn = UIButton()
        followBtn.layer.borderColor = UIColor.colorWithHexString(hexString:"#FFA500").cgColor
        followBtn.layer.borderWidth = 0.5
        followBtn.layer.cornerRadius = 12
        followBtn.clipsToBounds = true
        followBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        followBtn.setTitleColor(UIColor.colorWithHexString(hexString: "#FFA500"), for: UIControl.State.normal)
//        followBtn.addTarget(self, action: #selector(followBtnClick), for: UIControl.Event.touchUpInside)
        followBtn.setContentCompressionResistancePriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.horizontal)
        followBtn.setTitle("关注", for: UIControl.State.normal)
        followBtn.titleLabel?.textAlignment = NSTextAlignment.center
        return followBtn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }


    private func setupUI() {
        
        self.addSubview(nameL)
        self.addSubview(headImageView)
        self.addSubview(timeLabel)
        self.addSubview(followBtn)
        self.addSubview(membershipImageView)
        self.addSubview(avatarImageView)
        self.addSubview(sourceLabel)
        
        headImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(10)
            make.height.width.equalTo(35)
        }
        
        membershipImageView.snp_makeConstraints { (make) in
            make.centerY.equalTo(nameL.snp_centerY)
            make.left.equalTo(nameL.snp_right).offset(10)
            make.height.width.equalTo(15)
        }
        
        avatarImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(headImageView.snp_right)
            make.centerY.equalTo(headImageView.snp_bottom)
        }
        
        nameL.snp.makeConstraints { (make) in
            make.left.equalTo(headImageView.snp.right).offset(10)
            make.top.equalTo(headImageView.snp.top).offset(0)
            make.right.lessThanOrEqualTo(self.snp.right).offset(-5)//小于或等于
        }
        
        timeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameL.snp.left).offset(0)
            make.bottom.equalTo(headImageView.snp.bottom).offset(0)
            make.right.lessThanOrEqualTo(self.snp.right).offset(-5)
        }
        
        sourceLabel.snp_makeConstraints { (make) in
            make.left.equalTo(timeLabel.snp_right).offset(15)
            make.bottom.equalTo(headImageView.snp_bottom)
        }
        
        followBtn.snp.makeConstraints { (make) in
            make.right.equalTo(self).offset(-15)
            make.centerY.equalTo(headImageView.snp.centerY)
            make.height.equalTo(24)
            make.width.equalTo(60)
        }
    }
}
